<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		[#include "/html/include/easyuicss.html" /]
		[#include "/html/include/easyuijs.html" /]
		<script type="text/javascript" src="${app }/static/js/common.utils.js"></script>
		<style type="text/css">
			img {
				max-width: 80px;
			}
		</style>
	</head>
	<body class="easyui-layout" data-options="fit:true" style="overflow-y: hidden">
	<input type="hidden" id="accountId" name="accountId" value="${RequestParameters['accountId']}" />
	<table id="dgtable" class="easyui-datagrid" style="width:100%;height:100%;">
		<thead>
		<tr>
			<th data-options="field:'account_name',width:100">公众号名称</th>
			<th data-options="field:'open_id',width:220">OpenId</th>
			<th data-options="field:'nick_name',width:100">昵称</th>
			<th data-options="field:'sex',width:40">性别</th>
			<th data-options="field:'city',width:100">城市</th>
			<th data-options="field:'country',width:100">国家</th>
			<th data-options="field:'province',width:100">省份</th>
			<th data-options="field:'language',width:100">语言</th>
			<th data-options="field:'headimgurl',width:100,formatter:getImg">头像</th>
			<th data-options="field:'remark',width:100">备注</th>
			<th data-options="field:'subscribe2',width:80">关注</th>
			<th data-options="field:'operating',width:70,formatter:getBtn">操作</th>
		</tr>
		</thead>
	</table>
	<div id="tb">
		<span>昵称:</span>
		<input  class="easyui-textbox" id="nickName" name="nickName" />
		<a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="showList();">查询</a>
	</div>
	</body>
    <script type="text/javascript">
		$(document).ready(function(){
			$('#dgtable').datagrid({
				url: '${app}/weixin/user/list.do',
				method: 'post',
				queryParams: {accountId: $('#accountId').val(),nickName: $('#nickName').val()},
				singleSelect: true,
				rownumbers: true,
				toolbar: '#tb',
				onLoadSuccess: onLoadSuccess,
				pagination: true,
				pageSize: 20,
				pageList: [10,20,30]
			});
		});
		function getBtn(value, row, index) {
			var btnStr = '';
			if (row.subscribe == 0) {
				btnStr += '<a href="javascript:;" class="easyui-linkbutton" onclick="deleteInfo(\''+row.open_id+'\', \''+row.account_id+'\');">删除</a>&nbsp;';
			} else {
				btnStr += '<a href="javascript:;" class="easyui-linkbutton" onclick="getUserInfo(\''+row.open_id+'\', \''+row.account_id+'\', \''+row.id+'\');">拉取信息</a>&nbsp;';
			}
			return btnStr;
		}
		function getImg(value, row, index) {
			var btnStr = '';
			if (row.headimgurl != '' && row.headimgurl != undefined) {
				btnStr = '<img src="'+row.headimgurl+'" />';
			}
			return btnStr;
		}
		function onLoadSuccess(data){
			$('.easyui-linkbutton').linkbutton();
            $('#dgtable').datagrid('fixRowHeight');
		}
		function showList(){
			$('#dgtable').datagrid('load', {
				accountId: $('#accountId').val(),
				nickName: $('#nickName').val()
			});
		}
		function deleteInfo(openId, accountId){
			parent.easyui.confirm('系统提醒', '您确定要删除该条记录吗？', function(r){
				if (r){
					parent.layer.load(2);
					common.ajax('${app}/weixin/user/delete.do', 'openId='+openId+'&accountId='+accountId,
						'POST', 'json', false,
						function(result){
							parent.layer.closeAll('loading');
							parent.easyui.msgShow('系统提醒', result.msg, 3000, 250, 100);
							if (result.result == 1) {
								showList();
							}
						}
					);
				}
			});
		}
		function getUserInfo(openId, accountId, id){
			common.ajax('${app}/weixin/user/getUserInfo.do', 'openId='+openId+'&accountId='+accountId+'&id='+id,
					'POST', 'json', true,
					function(result){
						parent.layer.closeAll('loading');
						parent.easyui.msgShow('系统提醒', result.msg, 3000, 250, 100);
						if (result.result == 1) {
							showList();
						}
					}
			);
		}
    </script>
</html>